<table class="am-table am-table-striped am-form">
	<thead>
        <tr>
            <th style="width: 15%;">键名Key</th>
            <th style="width: 70%;">数值Value</th>
            <th style="width: 15%;">写入</th>
        </tr>
    </thead>
    <tbody id="blogCommonTb">
   		<tr>
   			<td class="blogCommonKey" data="blog_name">blogTitle</td>
   			<td class="changeInput">${blogCommon.blogTitle}</td>
   			<td>
               <button class="am-btn am-btn-primary am-btn-sm">
                 <i class="am-icon-fw am-icon-save"></i>
               </button>      
            </td>
   		</tr>
   		<tr>
   			<td class="blogCommonKey" data="blog_url">blogUrl</td>
   			<td class="changeInput">${blogCommon.blogUrl}</td>
   			<td>
               <button class="am-btn am-btn-primary am-btn-sm">
                 <i class="am-icon-fw am-icon-save"></i>
               </button>       
            </td>
   		</tr>
   		<tr>
   			<td class="blogCommonKey" data="blog_description">blogDescription</td>
   			<td class="changeInput">${blogCommon.blogDescription}</td>
   			<td>
               <button class="am-btn am-btn-primary am-btn-sm">
                 <i class="am-icon-fw am-icon-save"></i>
               </button>  
            </td>
   		</tr>
   		<tr>
   			<td class="blogCommonKey" data="blog_keywords">blogKeywords</td>
   			<td class="changeInput">${blogCommon.blogKeywords}</td>
   			<td>
               <button class="am-btn am-btn-primary am-btn-sm"><i class="am-icon-fw am-icon-save"></i></button>      
            </td>
   		</tr>
   		<tr>
   			<td class="blogCommonKey" data="blog_metas">blogMetas</td>
   			<td class="am-form-group"><textarea style="width:100%;" rows="5">${blogCommon.blogMetas}</textarea></td>
   			<td>
   				<button class="am-btn am-btn-primary am-btn-sm">
				     <i class="am-icon-fw am-icon-save"></i>
               </button>
   			</td>
   		</tr>
   		<tr>
   			<td class="blogCommonKey" data="blog_js">blogJs</td>
   			<td><textarea style="width:100%;" rows="10">${blogCommon.blogJs}</textarea></td>
   			<td>
               <button class="am-btn am-btn-primary am-btn-sm">
                 <i class="am-icon-fw am-icon-save"></i>
               </button>      
            </td>
   		</tr>
   		<tr>
   			<td class="blogCommonKey" data="blog_record">blogRecord</td>
   			<td class="changeInput">${blogCommon.blogRecord}</td>
   			<td>
               <button class="am-btn am-btn-primary am-btn-sm"><i class="am-icon-fw am-icon-save"></i></button>    
            </td>
   		</tr>
    </tbody>
</table>
<button id="id-update-all" class="am-btn am-btn-primary am-btn-lg">从数据库更新所有静态数据</button>
<script>
   function changedBlur(){
      var td = $(".changed");
      td.removeClass("changed");
      var valueStr = td.find("input").val();
      td.html(valueStr);
   }

	$(function(){
      $("#id-update-all").bind("click",function(){
         $.ajax({
            type : "post",
            data : {"${_csrf.parameterName}":"${_csrf.token}"},
            url  : "${rc.contextPath}/admin/settings/statics/update",
            success : function(result){
               alert(result.resultCode == 0 ? "更新成功" : result.message);
            },
            error : function(){alert("抱歉，来宾帐户无权对系统做出更改！")},
            dataType : "json"
         });
      });

      $(".changeInput").bind("click",function(){
         if(! $(this).hasClass("changed")){
            $(this).addClass("changed");
            var valueStr = $(this).html();
            $(this).html("<input type='text' onBlur='changedBlur()'>");
            $(this).find("input").focus().val(valueStr);
         }
      });

		$("#blogCommonTb button").bind("click",function(){
			var tr  = $(this).parents("tr");
			var key = tr.find(".blogCommonKey").attr("data");
			var value = tr.find(".changeInput").html() != undefined ? tr.find(".changeInput").html() : tr.find("textarea").val();

			$.ajax({
            type : "post",
            url  : "${rc.contextPath}/admin/settings/statics",
				data : {"key":key,"value":value,"${_csrf.parameterName}":"${_csrf.token}"},
				success : function(result){
					alert(result.resultCode == 0 ? "更新成功" : result.message);
				},
            error : function(){alert("抱歉，来宾帐户无权对系统做出更改！")},
            dataType : "json"
         });
		});
	});
</script>